import router from "@/router"
import {
    Message
} from 'element-ui'
import store from "@/store"
import admin from "@/api/main/admin";
export const topTabList = [
    {
        name: '操作端',
        index: 1,
        children: [{
            name: '项目审计管理系统',
            value: '1-1',
        }]
    },
    {
        name: '项目库',
        index: 2,
        children: [{
            name: '项目库管理',
            value: '2-1',
        },
        // {
        //     name: '审计项目进度查询',
        //     value: '2-2',
        // },
        {
            name: '项目查询',
            value: '2-2',
        }, {
            name: '某专题项目展示',
            value: '2-3',
        }]
    },
    {
        name: '价格库',
        index: 3,
        children: [{
            name: '价格查询',
            value: '3-1',
        },
        {
            name: '价格趋势',
            value: '3-2',
        }]
    },
    {
        name: '问题库',
        index: 4,
        children: [{
            name: '问题查询',
            value: '4-1',
        },
        {
            name: '标签管理',
            value: '4-2',
        },
        {
            name: '统计分析',
            value: '4-3',
        }]
    },
    {
        name: '法条库',
        index: 5,
        children: [{
            name: '法规查询',
            value: '5-1',
        }]
    },
    {
        name: '档案库',
        index: 6,
        children: [{
            name: '档案查询下载',
            value: '6-1',
        }]
    }
]
export function searchTabNameByValue(tabList, value) {
    for (let item of tabList) {
        for (let itemC of item.children) {
            if (itemC.value === value) {
                return itemC.name;
            }
        }
    }
}


export function selectPress(name) {

    if (name === "项目审计管理系统") {
        window.open('http://41.228.4.74:8800/web')
        // router.push({
        //   name: "auditResourceSystem",
        // });
    }
    else if (name === "档案查询下载") {
        router.history.current.name !== "documentLibrary" && router.push({
            name: "documentLibrary",
        });
    }
    else if (name === "法规查询") {
        router.history.current.name !== "regulatoryLibrary" && router.push({
            name: "regulatoryLibrary",
        });
    }
    else if (name === "项目库管理") {
        router.history.current.name !== "fileQuery" && router.push({
            name: "fileQuery",
        });
    }
    else if (name === "价格查询") {
        router.history.current.name !== "priceLibrary" && router.push({
            name: "priceLibrary",
        });
    }
    else if (name === "标签管理") {
        router.history.current.name !== "auditIssueLabel" && router.push({
            name: "auditIssueLabel",
        });
    }
    else if (name === "审计项目进度查询") {
        router.history.current.name !== "auditProjectProgressQuery" && router.push({
            name: "auditProjectProgressQuery",
        });
    }
    else if (name === "项目查询") {
        router.history.current.name !== "fileAdvancedQuery" && router.push({
            name: "fileAdvancedQuery",
        });
    }
    else if (name === "某专题项目展示") {
        router.history.current.name !== "displayOfSpecialProject" && router.push({
            name: "displayOfSpecialProject",
        });
    }
    else if (name === "价格趋势") {
        router.history.current.name !== "priceTrend" && router.push({
            name: "priceTrend",
        });
    }
    else if (name === "问题查询") {
        router.history.current.name !== "problemSearch" && router.push({
            name: "problemSearch",
        });
    }
    else if (name === "统计分析") {
        router.history.current.name !== "statisticalAnalysis" && router.push({
            name: "statisticalAnalysis",
        });
    }
    else if (name.indexOf('退出 ') !== -1) {
        window.localStorage.removeItem("role");
        store.dispatch("user/clearAll");
        router.push({
            name: "login",
        });
        admin.logout()
    } else {
        Message({
            message: '此功能还在开发中...,敬请期待!',
            type: 'warning'
        });
    }


}

export function hasPermission(name) {
    for (let item of topTabList) {
        for (let itemC of item.children) {
            let roleValue = window.localStorage.getItem("role");
            if (name === itemC.name) {
                if ((name=== "标签管理"||name=== "项目库管理"||name === "趋势分析") && (roleValue === "ywbm_ld" || roleValue === "xmdw_yw")) {
                    return false;
                }
            }
        }
    }
    return true;
}